package com.ynu.springbootappdemo.model.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.ynu.springbootappdemo.common.entity.BaseEntity;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import javax.persistence.*;
import java.util.List;

@Entity
@Getter
@Setter
@NoArgsConstructor
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler", "fieldHandler"})
public class Goods extends BaseEntity {
    @Column
    private String name;
    @Column
    private String picture;
    @Column
    private String description;
    @Column
    private Double price;
    @Column
    private String mainPictures;
    @Column
    private String descPictures;
    @Column
    private String properties;

    @OneToMany(mappedBy = "goods",
            fetch = FetchType.EAGER,
            orphanRemoval = true,
            cascade = CascadeType.ALL)
    @JsonIgnoreProperties(value = {"goods"})
    @Fetch(FetchMode.SUBSELECT)
    private List<CateGoods> cateGoods;

    @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.EAGER,orphanRemoval = true)
    @JoinColumn(name = "goods_id")
    @JsonIgnoreProperties("goods")
    @Fetch(FetchMode.SUBSELECT)
    private List<SkuItem> skuItems;


}
